package com.sy.server.mapper;

import com.sy.server.model.Login;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

public interface LoginMapper {

    @Select({
            "select count(*) as c from login",
            "where user_id = #{userId,jdbcType=INTEGER}",
            "and ip_addr = #{curIp,jdbcType=VARCHAR}"
    })
    @Results({
          @Result(column = "c",jdbcType = JdbcType.INTEGER)
    })
    int countByUserIdAndIp(Integer userId, String curIp);

    @Update({
            "update login",
            "set last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP}",
            "where user_id = #{userId,jdbcType=INTEGER}",
            "and ip_addr = #{ipAddr,jdbcType=VARCHAR}"
    })
    int updateLoginTime(Login login);

    @Insert({
            "insert into login(user_id,",
            "user_name,ip_addr,city_addr)",
            "values(#{userId,jdbcType=INTEGER},#{userName,jdbcType=VARCHAR},",
            "#{ipAddr,jdbcType=VARCHAR},#{cityAddr,jdbcType=VARCHAR})"
    })
    int insert(Login login);
}
